package cn.kgc.watch.service.impl;

import cn.kgc.watch.entity.Collect;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.kgc.watch.mapper.CollectMapper;
import cn.kgc.watch.service.CollectService;

import java.util.Date;
import java.util.List;

@Service
public class CollectServiceImpl implements CollectService{

    @Resource
    private CollectMapper collectMapper;

    @Override
    public void addCollect(Collect collect) {
        collect.setCreateTime(new Date());
        this.collectMapper.insert(collect);
    }

    @Override
    public Integer findCollectById(Integer id) {
        return this.collectMapper.selectCollectSkuById(id);
    }

    @Override
    public PageInfo<Collect> findAll(Integer userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Collect> collectList=this.collectMapper.selectAll(userId);
        PageInfo<Collect> pageInfo=new PageInfo<>(collectList);
        return pageInfo;
    }

    @Override
    public void add(Collect collect) {
        this.collectMapper.insert(collect);
    }

    @Override
    public void remove(Integer collectId) {
        this.collectMapper.delete(collectId);
    }
}
